package com.jk.controller.register;

import com.jk.constants.RegisterConstants;
import com.jk.pojo.PayAddress;
import com.jk.pojo.PayBank;
import com.jk.pojo.PayDict;
import com.jk.pojo.PayUser;
import com.jk.service.register.RegisterService;
import com.jk.util.ShortMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * &lt;pre&gt;项目名称：jk-pay
 * 类名称：注册页面的各种类
 * 创建人：李金春
 * 手机号：18839726119
 * 创建时间：${Time} ${Date}
 * 修改人：李金春
 * 修改时间：${Time} ${Date}
 * 修改备注：
 */
@RestController
@RequestMapping("reg")
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    /**页面加载查询省市县*/
    @GetMapping("selSSS")
    public List<List> selSSS(PayAddress address){
        List list = registerService.selSSS(address);
        return list;
    }
    /**页面加载查询职业*/
    @GetMapping("selProfession")
    public List selProfession(){
        List<PayDict> list = registerService.selProfession(RegisterConstants.REGISTER_PROFESSION_DICTNO);
        return list;
    }
    /**根据银行卡号获取银行预留手机号并发送验证码*/
    @GetMapping("bankShortMessage")
    public Map<String, String> bankShortMessage(PayBank bank, HttpServletRequest request){
        PayBank bankOne = registerService.selBankCardByBankCardId(bank);
        ShortMsg.shortMsg(bankOne.getReservedphone(),request);
        Map<String,String> map = (Map<String, String>) request.getSession().getAttribute("Info");
        return map;
    }
    /**根据用户手机号查看是否重复*/
    @GetMapping
    public Map<String,Integer> selUserPhone(PayUser user){
        //查询该用户手机号的集合
        List<PayUser> list = registerService.selUserPhoneByUserAccount(user.getUseraccount());
        Map<String,Integer> map = new HashMap<String,Integer>();
        //查看是否为空
        if(list.size() <= 0){
            map.put("flag",RegisterConstants.REGISTER_USERPHONE_CHECK_NULL);
        }else{
            map.put("flag", RegisterConstants.REGISTER_USERPHONE_CHECK_EXISTENCE);
        }
        return map;
    }
}
